package org.railage.server.entities;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.railage.common.dto.UserDTO;

/**
 * User entity
 * 
 * @author Cyril Fertikov
 * 
 */
@Entity
@Table(name = "user")
public class User implements Serializable {
	private static final long serialVersionUID = -625036428032713145L;

	@Id
	@GeneratedValue
	@Column(name = "id")
	private int id;

	@Column(name = "role")
	private int role;

	@Column(name = "login")
	private String login;

	@Column(name = "password")
	private String password;

	@Column(name = "name")
	private String name;

	@Column(name = "surname")
	private String surname;

	@Column(name = "birthday")
	private Date birthday;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
	private Set<Ticket> tickets;

	public User() {

	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getRole() {
		return role;
	}

	public void setRole(int role) {
		this.role = role;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public Set<Ticket> getTickets() {
		return tickets;
	}

	public void setTickets(Set<Ticket> tickets) {
		this.tickets = tickets;
	}

	public UserDTO toDTO() {
		UserDTO dto = new UserDTO();
		dto.setId(id);
		dto.setName(name);
		dto.setSurname(surname);
		dto.setBirthday(birthday);
		dto.setLogin(login);
		dto.setPassword(password);
		dto.setRole(role);
		return dto;
	}

	@Override
	public String toString() {
		return "User [id=" + id + ", role=" + role + ", login=" + login
				+ ", password=" + password + ", name=" + name + ", surname="
				+ surname + ", birthday=" + birthday + "]";
	}

}
